package video;

import org.gstreamer.Bin;
import org.gstreamer.Element;
import org.gstreamer.ElementFactory;
import org.gstreamer.GhostPad;
import org.gstreamer.Pad;
import org.gstreamer.swing.VideoComponent;

/**
 * Class that provide the tool to overlay a video with some text.
 * 
 * @version 0.3 December 01, 2009.
 * @author Heitor Meira de Melo.
 */
public class TextOverlay {
	private VideoComponent videoComponent;
	private Element videosink;
	private Element textoverlay;
	private Bin bin;
	private Pad pad;
	private GhostPad ghostpad;

	/**
	 * Constructor of a class that overlay a text over a video.
	 */
	@SuppressWarnings("deprecation")
	public TextOverlay() {
		textoverlay = ElementFactory.make("textoverlay", "TextOverlay");

		bin = new Bin("myBin");
		bin.add(textoverlay);

		pad = textoverlay.getPad("video_sink");

		ghostpad = new GhostPad("sink", pad);

		videoComponent = new VideoComponent();
		videosink = videoComponent.getElement();

		bin.addPad(ghostpad);
		bin.add(videosink);

		Element.linkMany(textoverlay, videosink);
	}

	/**
	 * Set the text to overlay.
	 * 
	 * @param text
	 *            The text.
	 */
	public void setText(String text) {
		textoverlay.set("text", text);
	}

	/**
	 * Set the size of the Text.
	 * 
	 * @param size
	 *            The size.
	 */
	public void setSize(int size) {
		textoverlay.set("font-desc", "Sans Bold " + size);
	}

	/**
	 * Set the y alignment in the screen.
	 * 
	 * @param y
	 *            the place of the alignment.
	 */
	public void setYAlignment(int y) {
		textoverlay.set("ypad", y);
	}

	/**
	 * Provides a VideoComponent synchronized with the other Element's.
	 * 
	 * @return The video Component
	 */
	public VideoComponent getVideoComponent() {
		return videoComponent;
	}

	/**
	 * Provides the textoverlay Element.
	 * 
	 * @return The textoverlay
	 */
	public Element getTextoverlay() {
		return textoverlay;
	}

	/**
	 * Provides the Bin Element in current use.
	 * 
	 * @return The Bin Element.
	 */
	public Element getBin() {
		return bin;
	}

	/**
	 * Provides the Pad in current use.
	 * 
	 * @return The Pad.
	 */
	public Pad getPad() {
		return pad;
	}

	/**
	 * Provides the GhostPad in current use.
	 * 
	 * @return The GhostPad.
	 */
	public GhostPad getGhostPad() {
		return ghostpad;
	}

	/**
	 * Provides the video sink element, synchronized with the others element's.
	 * 
	 * @return The video sink element.
	 */
	public Element getVideoSink() {
		return videosink;
	}
}
